
package com.ce.cases.source.logic.search;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import com.ce.cases.source.view.CaseSourceView;
import com.ce.framework.datamaintain.action.SearchAction;
import com.ce.framework.datamaintain.logic.ISQLMapper;
import com.ce.framework.datamaintain.logic.SQLSearchCondition;
import com.ce.framework.exception.AppException;
import com.ce.framework.util.DateUtil;
import com.ce.framework.util.StringUtil;
import com.ce.sys.login.model.User;

/**
* 嫦娥软件有限公司 版权所有 2013
* 创建人：　andy
* 创建日期：2014-03-18
* 创建时间：15:29:27
* 功能描述：备选案源台账 [CASE_SOURCE]条件过滤类
* ==============================================
* 修改历史
* 修改人		修改时间		修改原因
*
* ==============================================
*/
public class CaseSourceSearchCondition  extends SQLSearchCondition
	implements ISQLMapper
{

    private String taxpayerNum;
    private String involvedEnt;
    private String caseNum;
    private String recBeginDate;
    private String recEndDate;
    private String caseFrom;
    private String illegalType;
    private String inspectDept;
    private String collectDept;
    private String opMenu;
    private String curRootOrgId;
    private String curPersonId;
    private String curRootOrgLevel;
    private String curOrgId;
    private String vcAccept;//是否受理
    
   
	@Override
	public void initCondition(SearchAction action, boolean search)
			throws AppException {
		User user=User.getUser();
		curRootOrgId=user.getRootOrgId();
		curRootOrgLevel=user.getRootOrgLevel();
		curPersonId=user.getVcId();
		curOrgId=user.getVcOrgId();
	}
	@Override
	public String getExcelName() {
		String excelName="备选案源台账";
		if("approve".equals(opMenu)){
			excelName="稽查案源处理";
		}
		return excelName+"_"+DateUtil.format(new Date(),"yyyyMMddHHmm");
	}
	public String getExcelTitle(){
		String excelName="重庆市国家税务局";
		if("approve".equals(opMenu)){
			excelName=excelName+"稽查案源处理";
		}else{
			excelName=excelName+"稽查备选案源台账";
		}
		return excelName;
	}

	public String getSearchSql() throws AppException {
		
		StringBuffer sql = new StringBuffer("select * from CASE_SOURCE t where t.VC_DEL$FLAG = 0 and t.state!=3");
		if("2".equals(curRootOrgLevel))//跨区局
		{
			sql.append(" and t.REGISTER_DEPT_ID in (select t.vc_id from SYS_T_ORG t where t.vc_par$orgid='"+curRootOrgId+"') ");
			
		}else if("3".equals(curRootOrgLevel))//征管局，能看到登记部门是自己部门的。
		{
			sql.append(" and t.REGISTER_DEPT_ID='"+curRootOrgId+"'");
		}
		//采用变量绑定的方式提高查询效率
		if(StringUtil.isNotBlank(taxpayerNum)){
			sql.append(" and t.taxpayer_number like ${taxpayerNum}||'%'");
		}
		if(StringUtil.isNotBlank(involvedEnt)){
			sql.append(" and t.involved_enterprice like '%'||${involvedEnt}||'%'");
		}
		if(StringUtil.isNotBlank(caseNum)){
			sql.append(" and t.case_number=${caseNum}");
		}
		sql.append(this.getDateTimeCondition("REGISTER_DATE", recBeginDate, recEndDate));
		if(StringUtil.isNotBlank(caseFrom)){
			sql.append(" and t.case_from_num=${caseFrom}");
		}
		if(StringUtil.isNotBlank(illegalType)){
			sql.append(" and t.illegal_type_num=${illegalType}");
		}
		if(StringUtil.isNotBlank(inspectDept)){
			sql.append(" and t.inspection_dept_id=${inspectDept}");
		}
		if(StringUtil.isNotBlank(collectDept)){
			sql.append(" and t.collection_dept_id=${collectDept}");
		}
		if(StringUtil.isNotBlank(vcAccept)){
			sql.append(" and t.vc_accept=${vcAccept}");
		}
		//审批时进行状态过滤
		if("approve".equals(opMenu)){
			
		}
		//排序
		if(StringUtil.isNotBlank(this.order)){
            sql.append(" order by "+ this.getOrderByUnderLine()+",vc_id");
		}else{
			 sql.append(" order by register_date desc,vc_id");
		}
		return sql.toString();
	}
	
	public Object fromSQLQuery(ResultSet rs, int num) {
		CaseSourceView view = new CaseSourceView();
		try {
			view.setVcId(rs.getString("VC_ID"));
			view.setCaseNumber(rs.getString("CASE_NUMBER"));
			view.setRegisterPerson(rs.getString("REGISTER_PERSON"));
			view.setRegisterDeptId(rs.getString("REGISTER_DEPT_ID"));
			view.setRegisterDept(rs.getString("REGISTER_DEPT"));
			view.setRegisterDate(rs.getDate("REGISTER_DATE"));
			view.setTaxpayerNumber(rs.getString("TAXPAYER_NUMBER"));
			view.setInvolvedEnterprice(rs.getString("INVOLVED_ENTERPRICE"));
			view.setInspectionDeptId(rs.getString("INSPECTION_DEPT_ID"));
			view.setInspectionDept(rs.getString("INSPECTION_DEPT"));
			view.setCollectionDeptId(rs.getString("COLLECTION_DEPT_ID"));
			view.setCollectionDept(rs.getString("COLLECTION_DEPT"));
			view.setIsImportant(rs.getInt("IS_IMPORTANT"));
			view.setIsSecret(rs.getInt("IS_SECRET"));
			view.setCaseFromNum(rs.getString("CASE_FROM_NUM"));
			view.setCaseFromName(rs.getString("CASE_FROM_NAME"));
			view.setIllegalTypeNum(rs.getString("ILLEGAL_TYPE_NUM"));
			view.setIllegalTypeName(rs.getString("ILLEGAL_TYPE_NAME"));
			view.setReceiveDate(rs.getDate("RECEIVE_DATE"));
			view.setVcAaccept(rs.getString("vc_accept"));
			view.setReportId(rs.getString("REPORT_ID"));
			view.setVcDelFlag(rs.getInt("VC_DEL$FLAG"));			
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return view;
	}
	
	public ISQLMapper getSQLMapper() {
		
		return this;
	}

	public String getTaxpayerNum() {
		return taxpayerNum;
	}

	public void setTaxpayerNum(String taxpayerNum) {
		this.taxpayerNum = taxpayerNum;
	}

	

	public String getInvolvedEnt() {
		return involvedEnt;
	}

	public void setInvolvedEnt(String involvedEnt) {
		this.involvedEnt = involvedEnt;
	}

	public String getCaseNum() {
		return caseNum;
	}

	public void setCaseNum(String caseNum) {
		this.caseNum = caseNum;
	}

	public String getRecBeginDate() {
		return recBeginDate;
	}

	public void setRecBeginDate(String recBeginDate) {
		this.recBeginDate = recBeginDate;
	}

	public String getRecEndDate() {
		return recEndDate;
	}

	public void setRecEndDate(String recEndDate) {
		this.recEndDate = recEndDate;
	}

	public String getCaseFrom() {
		return caseFrom;
	}

	public void setCaseFrom(String caseFrom) {
		this.caseFrom = caseFrom;
	}

	public String getIllegalType() {
		return illegalType;
	}

	public void setIllegalType(String illegalType) {
		this.illegalType = illegalType;
	}

	public String getInspectDept() {
		return inspectDept;
	}

	public void setInspectDept(String inspectDept) {
		this.inspectDept = inspectDept;
	}

	public String getCollectDept() {
		return collectDept;
	}

	public void setCollectDept(String collectDept) {
		this.collectDept = collectDept;
	}

	public String getOpMenu() {
		return opMenu;
	}

	public void setOpMenu(String opMenu) {
		this.opMenu = opMenu;
	}

	

	public String getCurRootOrgId() {
		return curRootOrgId;
	}

	public void setCurRootOrgId(String curRootOrgId) {
		this.curRootOrgId = curRootOrgId;
	}

	public String getCurPersonId() {
		return curPersonId;
	}

	public void setCurPersonId(String curPersonId) {
		this.curPersonId = curPersonId;
	}
	public String getVcAccept() {
		return vcAccept;
	}
	public void setVcAccept(String vcAccept) {
		this.vcAccept = vcAccept;
	}

	
	

}

